$(function(){
	/**********填充时间*************/
	$u.clockon();
	setInterval($u.clockon,1000);
	/**********填充主题*************/
	$('#themeSelector').combobox({
		valueField: 'id',
		textField: 'text',
		data:[
		  {id:"default",text:"默认",selected:true},
		  {id:"gray",text:"灰色"},
		  {id:"bootstrap",text:"银色"},
		  {id:"ui-cupertino",text:"青色"}
		],
		onSelect: function(record){
				changeTheme(record.id);
		}
	});
	function changeTheme(themeName){
		var t=$('#theme');
		t.attr("href",$u.getRootPath()+"/plugins/jquery-easyui-theme/"+themeName+"/easyui.css");
		t.attr("type","text/css");
		t.attr("rel","stylesheet");
	    var $iframe = $('iframe');
	    if ($iframe.length > 0) {
	        for ( var i = 0; i < $iframe.length; i++) {
	           var ifr = $iframe[i];
	           $(ifr).contents().find('#theme').attr('href', $u.getRootPath()+"/plugins/jquery-easyui-theme/"+themeName+"/easyui.css");
	        }
	    }
	    $.cookie('theme', themeName, {
	    	expires : 30,
	    	path: '/'
	    });
	}
	/**********折叠北部*************/
	$("#btnHideNorth").click(
		function () { 
			$(main).layout("collapse", "north");
		}
	);
	/**********退出系统*************/
	$("#btnExit").click(
		function(){
			if (window.confirm("确认要退出系统？")) {
				window.location.href = $u.getRootPath()+'/user/exit';
			}
		}
	);
	/**********个人信息*************/
	$("#btnUser").click(
		function(){
			$.messager.alert("提示", "个人信息！", "info");
		}
	);
	/**********跳转至主页*************/
	$("#mainTabs_jumpHome").click(
		function(){
			$('#mainTabs').tabs('select',0);
		}
	);
	var type="collapse";
	/**********最大/小化*************/
	$("#mainTabs_toggleAll").click(
		function(){
			$(main).layout(type,"north");
			$(main).layout(type,"south");
			$(main).layout(type,"west");
			$(main).layout(type,"east");
			if(type=="collapse"){
				type="expand";
			}else{
				type="collapse";
			}
		}
	);
	/**********刷新tab*************/
	$("#mainTabs_refTab").click(
		function(){
			var tab = $('#mainTabs').tabs('getSelected');  
			$('#mainTabs').tabs('update', {
				tab: tab,
				options: {
					title: tab.panel('options').title,
					content: tab.panel('options').content  
				}
			});
		}
	);
	/**********关闭全部tab*************/
	$("#mainTabs_closeTab").click(
		function(){
			var allTabs = $("#mainTabs").tabs('tabs');
		    for(var i = 0, len = allTabs.length; i < len; i++) {
		      $("#mainTabs").tabs('close', 1);
		    }
		}
	);
	/**********全屏切换*************/
	$("#btnFullScreen").click(
	   function(){
		   if (fullScreenApi.supportsFullScreen) {
			   if(!fullScreenApi.isFullScreen()){
				   fullScreenApi.requestFullScreen(document.documentElement);
			   }else{
				   fullScreenApi.cancelFullScreen(document.documentElement);
			   }
			}else{
				alert("您的浏览器不支持全屏API，请换高版本的chrome或者firebox！");
			}
	   }
	);
	/**********主页显示chart*************/
	$.ajax({
        url:$u.getRootPath()+'/lrb/getSZ',
        dataType:'json',  
        success:function(data){
        	if (data.success == false) {
				$.messager.alert("提示",
						data.msg, "error");
			} else {
				var date = new Array();
				var sr = new Array();
				var fy = new Array();
				var lr = new Array();
                $.each(data, function(i, item) {
                	date[i] = item.date;
                    sr[i] = item.sr;
                	fy[i] = item.fy;
                	lr[i] = item.lr;
                });
				var chart = new Highcharts.Chart('chart', {
				    title: {
				        text: '收支变化趋势',
				    },
				    xAxis: {
				        categories: date
				    },
				    yAxis: {
				        title: {
				            text: '金额（元）'
				        },
				        plotLines: [{
				            value: 0,
				            width: 1,
				            color: '#808080'
				        }]
				    },
				    legend: {
				        layout: 'vertical',
				        align: 'right',
				        verticalAlign: 'middle',
				        borderWidth: 0
				    },
				    series: [{
				        name: '收入',
				        data: sr
				    }, {
				        name: '费用',
				        data: fy
				    }, {
				        name: '利润',
				        data: lr
				    }]
				});

			}
        },error : function() {
			$.messager.alert('提示', "错误",
			"error");
        }
	});
});
/**********添加tab*************/
function addTab(title, url) {
	if ($('#mainTabs').tabs('exists', title)) {
		$('#mainTabs').tabs('select', title);
	} else {
		var content = '<iframe scrolling="auto" frameborder="0"  src="' + url
				+ '" style="width:100%;height:100%"></iframe>';
		$('#mainTabs').tabs('add', {
			title : title,
			content : content,
			closable : true
		});
	}
};